/**
 * Created with Vim7.3 ubuntu12.04
 * @fileOverview : 
 * @author : Lyle <lylechen2014@gmial.com>
 * @since : 2014-09-10 16:27:47
 * @filename : static/sea-modules/tab/zepto.tabA.js
 * @version : 
 * @description : 
 */

;(function(){

    var DW = window.innerWidth,
        MT = 200;

    $.fn.tabA = {
        
         opt : {
             index : 0,
             tabs : 3,
             dom : '#joinus_tabs',
             sonClass : 'joinus_tab'
         },
        
         init : function(opt) {
              var tthis = this;
              
              for (var i in opt ) {
                   this.opt[i] = opt[i];
              }

              $(this.opt.dom).find('.'+this.opt.sonClass).eq(this.opt.index).css({
                 'display':'block'
              });

              $(window).bind('orientationchange',function(){
                  DW = window.innerWidth;
              });
         },

         gotoTabs : function(index) {
               index = this.tabIndexCondtion(index);
               if (index < this.opt.index) {
                   this.rightTabs(this.opt.index,false);
                   this.rightTabs(index,true);
               } else if (index > this.opt.index) {
                   this.leftTabs(this.opt.index,false);
                   this.leftTabs(index,true)
               }
               this.opt.index = index;
         }, 

         leftTabs : function(index,bool) {
              var tthis = this,SDOM = $(this.opt.dom).find('.'+this.opt.sonClass).eq(index);
              if (bool) {
                  SDOM.css({
                       'display':'block', 
                       'left': DW+'px',
                       'z-index':1
                  });
                  setTimeout(function(){
                    tthis.transformCSS(SDOM,0,MT);
                  },100);
              } else {
                  SDOM.css({'z-index':0});
                  setTimeout(function(){
                      SDOM.css({'display':'none'});
                  },MT+150);
              }
         },
         
         rightTabs : function(index,bool) {
              var tthis = this,SDOM = $(this.opt.dom).find('.'+this.opt.sonClass).eq(index);
              if (bool) {
                  SDOM.css({
                       'display':'block', 
                       'left': -DW+'px',
                       'z-index' : 1 
                  });
                  setTimeout(function(){
                       tthis.transformCSS(SDOM,0,MT);
                  },100);
              } else {   
                  SDOM.css({'z-index':0});
                  setTimeout(function(){
                      SDOM.css({
                          'display':'none', 
                      });
                  },MT+150);
              }
         },
         
         //css 动画 
         transformCSS : function(dom,move,time) {
             //fixedBUG,postion定位问题
             dom.css({'transition':time+'ms linear;','left':move});
         },  

         tabIndexCondtion : function(index) {
               if (index < 0) {
                   index = 0 ;
               } else if (index > this.opt.tabs-1) {
                   index = this.opt.tabs-1;
               }
               return index;
         }
    }

    if (typeof define === "function" ) {
        define("tab/zepto.tabA.js", [], function () { return $.fn.tabA;} );
    }



})();

